@extends('admin.public.base')


@section('title', '编辑角色权限角色')

@section('content')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>角色管理 <span
                class="c-gray en">&gt;</span> 编辑角色权限 <a class="btn btn-success radius r"
                                                        style="line-height:1.6em;margin-top:3px"
                                                        href="javascript:location.replace(location.href);" title="刷新"><i
                    class="Hui-iconfont">&#xe68f;</i></a></nav>

    <form action="" method="post" class="form form-horizontal" id="form-article-add">
        @csrf
        <div class="Hui-article">
            <article class="cl pd-20">

                <div class="mt-20">
                    <table class="table table-border table-bordered table-bg table-hover table-sort">
                        <thead>
                        <tr class="text-c">
                            <th width="10%">权限吗</th>
                            <th width="90%">子权限</th>
                        </tr>
                        </thead>
                        <tbody>

                        {{--遍历权限--}}
                        @foreach($allPermissDatas as $allPermissData)
                            <tr>
                                <td>
                                    <label>
                                        <input
                                                @if(in_array($allPermissData['id'],$currentPermissArr))
                                                checked
                                                @endif
                                                name="permissions[]"
                                                type="checkbox"
                                                value="{{$allPermissData['name']}}">
                                        {{$allPermissData['describe']}}
                                    </label>
                                </td>

                                <td class="childtd">
                                    @foreach($allPermissData['_data'] as $childPermissData )
                                        <label>
                                            <input
                                                    @if(in_array($childPermissData['id'],$currentPermissArr))
                                                    checked
                                                    @endif
                                                    name="permissions[]"
                                                    type="checkbox"
                                                    value="{{$childPermissData['name']}}">
                                            {{$childPermissData['describe']}}
                                        </label>
                                    @endforeach
                                </td>
                            </tr>
                        @endforeach
                        <style>
                            #endselect {
                                display: none
                            }
                        </style>

                        <tr>
                            <td>
                                <span class="l">
                                    <button id="allselect" type="button" class="btn btn-primary radius">
                                        <i class="Hui-iconfont">&#xe651;</i> 全选
                                    </button>

                                     <button id="endselect" type="button" class="btn btn-primary radius">
                                        <i class="Hui-iconfont">&#xe651;</i> 反选
                                    </button>

                                </span>
                            </td>
                            <td>
                                 <span class="l">
                                    <button type="submit" onclick="return confirm('确认提交保存?')"
                                            class="btn btn-warning radius">
                                        <i class="Hui-iconfont">&#xe632;</i> 保存
                                    </button>
                                      <button onClick="history.back();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
                                </span>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </article>
        </div>
    </form>
@endsection

@section('script')
    <script>
        //子类全选
        $('input[type=checkbox]').click(function () {
            if ($(this).prop('checked')) {
                $(this).parents('td').siblings('.childtd').find('input[type=checkbox]').prop("checked", true);
            } else {
                $(this).parents('td').siblings('.childtd').find('input[type=checkbox]').prop("checked", false);
            }
        });
        //全选
        $('#allselect').click(
            function () {
                $("[type='checkbox']").prop("checked", true);
                $(this).hide();
                $('#endselect').show();
            }
        );
        //反选
        $('#endselect').click(
            function () {
                $("[type='checkbox']").prop("checked", false);
                $(this).hide();
                $('#allselect').show();
            }
        );
    </script>
@endsection